#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
const int N = 15;
int a[15][5];
int cnt[15];
int n = 13;
int m = 4;
void dfs(int s)
{
    if (s == 13)
        return;
    int t = a[s][cnt[s]];
    cnt[s]--;
    dfs(t);
}
int main()
{
    for (int i = 1; i <= 13; i++)
    {
        cnt[i] = 4;
        for (int j = 1; j <= 4; j++)
        {
            char x;
            cin >> x;
            if (x >= '2' && x <= '9') a[i][j] = x - '0';
            else if (x == 'A') a[i][j] = 1;
            else if (x == 'J') a[i][j] = 11;
            else if (x == 'Q') a[i][j] = 12;
            else if (x == 'K') a[i][j] = 13;
            else a[i][j] = 10;
        }
    }
    for (int i = 1; i <= 4; i++)
    {
        int t = a[13][i];
        dfs(t);
    }
    int ret = 0;
    for (int i = 1; i <= n; i++)
    {
        if (cnt[i] == 0)
            ret++;
    }
    cout << ret;
    return 0;
}